<%@ page import="csc309.Flight" %>
<%@ page import="csc309.Validator" %>
<%

if (!Validator.validSeat(request)) {
	//TODO: redirect loop reset post headers so they can start over, or send to main page
	//response.sendRedirect(request.getHeader("referer"));
	out.println("Invalid");
	return;
}

String from = request.getParameter("from");
String to = from.equals("Toronto") ? "Montreal" : "Toronto";
int day = Integer.parseInt(request.getParameter("day"));
int month = Integer.parseInt(request.getParameter("month"));
int year = Integer.parseInt(request.getParameter("year"));
int seat = Integer.parseInt(request.getParameter("seat"));
int time = (seat / 3 + 1) * 10;
seat = seat % 3 + 1;

Flight f = new Flight(from, to, day, month, year, time);

if (f.isSeatTaken(seat)) {
	out.println("Sorry this seat has been taken!");
	return;
}
f.takeSeat(seat);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>MileHigh Airlines</title>
	<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>

<body>

<pre id="receipt">
The cost of your ticket is $100.

From: <%= from %>
To: <%= to %>
Time: <%= time == 10 ? "10:00 am" : "8:00 pm" %>
Day: <%= day %>
Month: <%= month + 1 %>
Year: <%= year %>
Seat: <%= seat %>
</pre>

<button class="blue-pill" onClick="window.print()">Print</button>
</body>

</html>